<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Wrapper function</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Wrapper_function"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Wrapper_function rootpage-Wrapper_function skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Wrapper function</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<style data-mw-deduplicate="TemplateStyles:r1236090951">
/* start https://en.wikipedia.org/ */
.mw-parser-output .hatnote{font-style:italic}.mw-parser-output div.hatnote{padding-left:1.6em;margin-bottom:0.5em}.mw-parser-output .hatnote i{font-style:normal}.mw-parser-output .hatnote+link+.hatnote{margin-top:-0.5em}@media print{body.ns-0 .mw-parser-output .hatnote{display:none!important}}
/* end https://en.wikipedia.org/ */
</style><div role="note" class="hatnote navigation-not-searchable">This article is about programming structure. For wrapping in graphics, see <a href="Wrapping_(graphics)" title="Wrapping (graphics)">Wrapping (graphics)</a>.</div>
<div role="note" class="hatnote navigation-not-searchable">"Wrapper method" redirects here. For wrapper methods in feature selection, see <a href="Feature_selection#Wrapper_method" title="Feature selection">Feature selection § Wrapper method</a>.</div>
<p>A <b>wrapper function</b> is a <a href="Function_(computer_programming)" title="Function (computer programming)">function</a> (another word for a <i>subroutine</i>) in a <a href="Library_(computing)" title="Library (computing)">software library</a> or a <a href="Computer_program" title="Computer program">computer program</a> whose main purpose is to call a second subroutine<sup id="cite_ref-1" class="reference"><a href="#cite_note-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> or a <a href="System_call" title="System call">system call</a> with little or no additional computation. Wrapper functions simplify writing computer programs by abstracting the details of a subroutine's implementation.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="Purpose">Purpose</h2></div>
<p>Wrapper functions are a means of <a href="Delegation_(programming)" class="mw-redirect" title="Delegation (programming)">delegation</a> and can be used for a number of purposes.
</p>
<div class="mw-heading mw-heading3"><h3 id="Programming_convenience">Programming convenience</h3></div>
<p>Wrapper functions simplify writing computer programs. For example, the <code>MouseAdapter</code> and similar classes in the <a href="Java_AWT" class="mw-redirect" title="Java AWT">Java AWT</a> library demonstrate this.<sup id="cite_ref-2" class="reference"><a href="#cite_note-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup>
They are useful in the development of applications that use third-party library functions. A wrapper can be written for each of the third party functions and used in the native application. In case the third party functions change or are updated, only the wrappers in the native application need to be modified as opposed to changing all instances of third party functions in the native application.
</p>
<div class="mw-heading mw-heading3"><h3 id="Adapting_class/object_interfaces">Adapting class/object interfaces</h3></div>
<div role="note" class="hatnote navigation-not-searchable">Main article: <a href="Adapter_pattern" title="Adapter pattern">Adapter pattern</a></div>
<p>Wrapper functions can be used to <a href="Adapter_pattern" title="Adapter pattern">adapt</a> an existing class or object to have a different interface. This is especially useful when using existing library code.
</p>
<div class="mw-heading mw-heading3"><h3 id="Code_testing">Code testing</h3></div>
<p>Wrapper functions can be used to write <a href="Debugger" title="Debugger">error checking</a> routines for pre-existing system functions without increasing the length of a code by a large amount by repeating the same error check for each call to the function.<sup id="cite_ref-3" class="reference"><a href="#cite_note-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup> All calls to the original function can be replaced with calls to the wrapper, allowing the programmer to forget about error checking once the wrapper is written.
A test driver is a kind of wrapper function that exercises a code module, typically calling it repeatedly, with different settings or parameters, in order to rigorously pursue each possible path. It is not deliverable code, but it is not throwaway code either, being typically retained for use in <a href="Regression_testing" title="Regression testing">regression testing</a>.
An interface adaptor is a kind of wrapper function that simplifies, tailors, or amplifies the interface to a code module, with the intent of making it more intelligible or relevant to the user. It may rename parameters, combine parameters, set defaults for parameters, and the like.
</p>
<div class="mw-heading mw-heading3"><h3 id="Multiple_inheritance">Multiple inheritance</h3></div>
<p>In a <a href="Programming_language" title="Programming language">programming language</a> that does not support <a href="Multiple_inheritance" title="Multiple inheritance">multiple inheritance</a> of base classes, wrapper functions can be used to simulate it. Below is an example of part of a <a href="Java_(programming_language)" title="Java (programming language)">Java</a> class that "inherits" from LinkedList and HashSet. See <a href="Method_(computer_programming)" title="Method (computer programming)">method</a> for further implementation details.
</p>
<div class="mw-highlight mw-highlight-lang-java mw-content-ltr" dir="ltr"><pre><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Test</span><span class="w"> </span><span class="kd">implements</span><span class="w"> </span><span class="n">LinkedList</span><span class="p">,</span><span class="w"> </span><span class="n">HashSet</span><span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="nd">@Override</span>
<span class="w"> </span><span class="c1">// contains data members and data methods</span>
<span class="w"> </span><span class="c1">// covariant return</span>
<span class="p">}</span>
</pre></div>
<div class="mw-heading mw-heading2"><h2 id="Library_functions_and_system_calls">Library functions and system calls</h2></div>
<p>Many <a href="Standard_library" title="Standard library">library</a> functions, such as those in the <a href="C_Standard_Library" class="mw-redirect" title="C Standard Library">C Standard Library</a>, act as <a href="Interface_(computing)" title="Interface (computing)">interfaces</a> for <a href="Abstraction_(computer_science)" title="Abstraction (computer science)">abstraction</a> of <a href="System_call" title="System call">system calls</a>. The <i>fork</i> and <i>execve</i> functions in <a href="Glibc" title="Glibc">glibc</a> are examples of this. They call the <a href="Low-level" class="mw-redirect" title="Low-level">lower-level</a> <i><a href="Fork_(operating_system)" class="mw-redirect" title="Fork (operating system)">fork</a></i> and <i><a href="Execve" class="mw-redirect" title="Execve">execve</a></i> system calls, respectively.
</p><p>This may lead to incorrectly using the terms "system call" and "syscall" to refer to higher-level library calls rather than the similarly named system calls, which they wrap.<sup id="cite_ref-4" class="reference"><a href="#cite_note-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-5" class="reference"><a href="#cite_note-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="Helper_function">Helper function</h2></div>
<p>A helper function is a function which groups parts of <a href="Computation" title="Computation">computation</a> by assigning descriptive names and allowing for the reuse of the computations.<sup id="cite_ref-6" class="reference"><a href="#cite_note-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup> Although not all wrappers are helper functions, all helper functions are wrappers, and a notable use of helper functions—grouping frequently utilized operations—is in <a href="Binary_translation#Dynamic_binary_translation" title="Binary translation">dynamic binary translation</a>, in which helper functions of a particular <a href="Computer_architecture" title="Computer architecture">architecture</a> are used in translation of <a href="Machine_code" title="Machine code">instructions</a> from one <a href="Instruction_set_architecture" title="Instruction set architecture">instruction set</a> into another.<sup id="cite_ref-7" class="reference"><a href="#cite_note-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="Wrapper_library" title="Wrapper library">Wrapper library</a></li>
<li><a href="Driver_wrapper" title="Driver wrapper">Driver wrapper</a></li>
<li><a href="Adapter_pattern" title="Adapter pattern">Adapter pattern</a></li>
<li><a href="Decorator_pattern" title="Decorator pattern">Decorator pattern</a></li>
<li><a href="Delegation_(programming)" class="mw-redirect" title="Delegation (programming)">Delegation (programming)</a></li>
<li><a href="Forwarding_(object-oriented_programming)" title="Forwarding (object-oriented programming)">Forwarding (object-oriented programming)</a></li>
<li><a href="Language_binding" title="Language binding">Language binding</a> wrapper to another language</li>
<li><a href="SWIG" title="SWIG">SWIG</a> automatic wrapper generator</li>
<li><a href="Nested_function" title="Nested function">Nested function</a></li>
<li><a href="Partial_application" title="Partial application">Partial application</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */
.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}
/* end https://en.wikipedia.org/ */
</style><div class="reflist">
<div class="mw-references-wrap"><ol class="references">
<li id="cite_note-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-1">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */
.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}
/* end https://en.wikipedia.org/ */
</style><cite id="CITEREFReselmanPeasley,_RichardPruchniak,_Wayne1998" class="citation book cs1">Reselman, Bob; Peasley, Richard; Pruchniak, Wayne (1998). <a rel="nofollow" class="external text" href="https://books.google.com/books?id=X5ZQAAAAMAAJ"><i>Using Visual Basic 6</i></a>. Que. p. 446. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>9780789716330</bdi>.</cite></span>
</li>
<li id="cite_note-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-2">^</a></b></span> <span class="reference-text"><a rel="nofollow" class="external text" href="https://java.sun.com/docs/books/tutorial/uiswing/events/mouselistener.html">The Java Tutorials</a></span>
</li>
<li id="cite_note-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-3">^</a></b></span> <span class="reference-text"><cite id="CITEREFStevensFenner,_BillRudoffAndrew_M.2003" class="citation book cs1">Stevens, Richard; Fenner, Bill; Rudoff; Andrew M. (2003). <a rel="nofollow" class="external text" href="https://books.google.com/books?id=ptSC4LpwGA0C"><i>UNIX Network Programming</i></a>. Addison-Wesley. pp. <span class="nowrap">5–</span>6, 29. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>9780131411555</bdi>.</cite></span>
</li>
<li id="cite_note-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-4">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://man7.org/linux/man-pages/man2/syscalls.2.html">"syscalls(2) - Linux manual page"</a>. <i>man7.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2020-04-25</span></span>.</cite></span>
</li>
<li id="cite_note-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-5">^</a></b></span> <span class="reference-text"><cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://www.gnu.org/software/libc/manual/html_node/System-Calls.html">"System Calls (The GNU C Library)"</a>. <i>www.gnu.org</i><span class="reference-accessdate">. Retrieved <span class="nowrap">2020-04-25</span></span>.</cite></span>
</li>
<li id="cite_note-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-6">^</a></b></span> <span class="reference-text"><cite id="CITEREFFisler2005" class="citation web cs1">Fisler, Kathi (2005). <a rel="nofollow" class="external text" href="https://web.cs.wpi.edu/~cs1101/a05/Docs/creating-helpers.html">"CS 1101: Helper functions"</a>. <a href="Worcester_Polytechnic_Institute" title="Worcester Polytechnic Institute">Worcester Polytechnic Institute</a>. <a rel="nofollow" class="external text" href="https://web.archive.org/web/20210507033146/https://web.cs.wpi.edu/~cs1101/a05/Docs/creating-helpers.html">Archived</a> from the original on 7 May 2021<span class="reference-accessdate">. Retrieved <span class="nowrap">17 November</span> 2021</span>.</cite></span>
</li>
<li id="cite_note-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-7">^</a></b></span> <span class="reference-text"><cite id="CITEREFWang2021" class="citation conference cs1">Wang, Wenwen (3 March 2021). <span class="id-lock-subscription" title="Paid subscription required"><a rel="nofollow" class="external text" href="https://dl.acm.org/doi/10.1145/3446804.3446851"><i>Helper function inlining in dynamic binary translation</i></a></span>. CC: Compiler Construction. New York, United States: <a href="Association_for_Computing_Machinery" title="Association for Computing Machinery">Association for Computing Machinery</a>. p. 107. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F3446804.3446851">10.1145/3446804.3446851</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a> <bdi>978-1-4503-8325-7</bdi>.</cite></span>
</li>
</ol></div></div></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-06-03" href="https://en.wikipedia.org/wiki/?title=Wrapper_function&oldid=1293763377">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>
</body></html>